<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      /* 
 Date对象是内置的存储日期和时间的对象 
 通过构造方法得到对象后可以获取其中的一些和时间与日期相关的内容

*/
      function gen(){
        var now = new Date();//当前日期时间
    /*   var now1 = new Date("2022/01/01"); 指定时间
      let d = new Date("July 30 1992 18:30"); */  // 日期字符串方法

      
        //通过对象的方法获取信息
        var year = now.getFullYear()+"年";
        var month = now.getMonth() + 1 + "月";
        var day = now.getDate()+"日";
        var hours = now.getHours() + "时";
        var minutes = now.getMinutes() + "分";
        var sconds = now.getSeconds() + "秒";
        console.log(year + month + day + hours + minutes + sconds);
       /*  document.write(year + month + day + hours + minutes + sconds); */
       /* document.querySelector("div").innerHTML=year + month + day + hours + minutes + sconds; */
       document.querySelector("div").innerHTML= hours + minutes + sconds;
      }


      setInterval(gen,1000);
      // gen();
        

    </script>
  </head>
  <body>
    <div style="width: 300px; height: 200px; background:pink; font-size: 60px"></div>
  </body>
</html>
